package o;

import com.google.android.exoplayer2.ParserException;
import com.huawei.hms.common.data.DataBufferSafeParcelable;
import java.io.IOException;

final class ahf {

    static final class a {
        public final int ˋ;
        public final long ˎ;

        private a(int i, long j) {
            this.ˋ = i;
            this.ˎ = j;
        }

        public static a ˏ(adv o_adv, anc o_anc) throws IOException, InterruptedException {
            o_adv.ˎ(o_anc.ˏ, 0, 8);
            o_anc.ˋ(0);
            return new a(o_anc.ॱᐝ(), o_anc.ॱˊ());
        }
    }

    public static agx ˊ(adv o_adv) throws IOException, InterruptedException {
        amm.ॱ(o_adv);
        anc o_anc = new anc(16);
        if (a.ˏ(o_adv, o_anc).ˋ != act.ॱ) {
            return null;
        }
        o_adv.ˎ(o_anc.ˏ, 0, 4);
        o_anc.ˋ(0);
        int ॱᐝ = o_anc.ॱᐝ();
        if (ॱᐝ != act.ˊ) {
            amz.ˋ("WavHeaderReader", "Unsupported RIFF format: " + ॱᐝ);
            return null;
        }
        a ˏ = a.ˏ(o_adv, o_anc);
        while (ˏ.ˋ != act.ˎ) {
            o_adv.ˊ((int) ˏ.ˎ);
            ˏ = a.ˏ(o_adv, o_anc);
        }
        amm.ˏ(ˏ.ˎ >= 16);
        o_adv.ˎ(o_anc.ˏ, 0, 16);
        o_anc.ˋ(0);
        int ʼ = o_anc.ʼ();
        int ʼ2 = o_anc.ʼ();
        int ʾ = o_anc.ʾ();
        int ʾ2 = o_anc.ʾ();
        int ʼ3 = o_anc.ʼ();
        int ʼ4 = o_anc.ʼ();
        int i = (ʼ2 * ʼ4) / 8;
        if (ʼ3 != i) {
            throw new ParserException("Expected block alignment: " + i + "; got: " + ʼ3);
        }
        i = act.ॱ(ʼ, ʼ4);
        if (i == 0) {
            amz.ˋ("WavHeaderReader", "Unsupported WAV format: " + ʼ4 + " bit/sample, type " + ʼ);
            return null;
        }
        o_adv.ˊ(((int) ˏ.ˎ) - 16);
        return new agx(ʼ2, ʾ, ʾ2, ʼ3, ʼ4, i);
    }

    public static void ˎ(adv o_adv, agx o_agx) throws IOException, InterruptedException {
        amm.ॱ(o_adv);
        amm.ॱ(o_agx);
        o_adv.ˏ();
        anc o_anc = new anc(8);
        a ˏ = a.ˏ(o_adv, o_anc);
        while (ˏ.ˋ != anr.ᐝ(DataBufferSafeParcelable.DATA_FIELD)) {
            amz.ˏ("WavHeaderReader", "Ignoring unknown WAV chunk: " + ˏ.ˋ);
            long j = 8 + ˏ.ˎ;
            if (ˏ.ˋ == anr.ᐝ("RIFF")) {
                j = 12;
            }
            if (j > 2147483647L) {
                throw new ParserException("Chunk is too large (~2GB+) to skip; id: " + ˏ.ˋ);
            }
            o_adv.ॱ((int) j);
            ˏ = a.ˏ(o_adv, o_anc);
        }
        o_adv.ॱ(8);
        o_agx.ॱ(o_adv.ˊ(), ˏ.ˎ);
    }
}
